package com.huixh.train.member.controller;

import com.huixh.train.common.context.LoginMemberContext;
import com.huixh.train.common.resp.PageResult;
import com.huixh.train.common.resp.Result;
import com.huixh.train.member.req.PassengerQueryReq;
import com.huixh.train.member.req.PassengerSaveReq;
import com.huixh.train.member.resp.PassengerQueryResp;
import com.huixh.train.member.service.PassengerService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author huixh
 */
@Tag(name = "PassengerController", description = "乘客服务")
@Validated
@RestController
@RequestMapping("/passenger")
public class PassengerController {
    @Resource
    private PassengerService passengerService;

    @PostMapping("/save")
    @Operation(summary = "保存乘客信息或编辑", method = "POST")
    public Result<?> save(@RequestBody @Valid PassengerSaveReq passengerSaveReq) {
        passengerService.save(passengerSaveReq);
        return Result.success();
    }

    @PostMapping("/quest-list")
    @Operation(summary = "查询乘客列表", method = "POST")
    public PageResult<List<PassengerQueryResp>> query(@RequestBody @Valid PassengerQueryReq passengerQueryReq) {
        Long memberId = LoginMemberContext.getMemberId();
        passengerQueryReq.setMemberId(memberId);
        return passengerService.queryList(passengerQueryReq);
    }

    @Operation(summary = "删除乘客信息", method = "DELETE")
    @DeleteMapping("/delete/{id}")
    public Result<?> delete(@NotNull @PathVariable(name = "id") Long id) {
        passengerService.delete(id);
        return Result.success("删除成功");
    }
    @Operation(summary = "查询我的乘客信息", method = "GET")
    @GetMapping("/query-mine")
    public Result<List<PassengerQueryResp>> queryMine() {
        List<PassengerQueryResp> queryResps = passengerService.queryMine();
        return Result.success(queryResps);
    }
}
